
//
//  TaskDetailController.m
//  PASystem
//
//  Created by 刘沿 on 16/9/23.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "TaskDetailController.h"
#import "TaskDetailModel.h"
#import "TaskDetailCell.h"
#import "PersonTaskController.h"

@interface TaskDetailController ()
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,assign) int currentPage;
@end

@implementation TaskDetailController
static NSString *const reuseID = @"TaskDetailCell";

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    [self loadData];
}

- (void)loadData{
    
    self.currentPage = 1;
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json = [NSString stringWithFormat:@"{'action': xxrwxxMch,'service': PartydeptService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@,pageNum:%d}'}",userId,pwdId,userHumber,self.ID,self.currentPage];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        NSArray *dictArr = JSON[@"reason"];
        
        if (dictArr) {
            for (NSDictionary *dict in dictArr) {
                NSDictionary *dict2 = dict[@"attrs"];
                
                TaskDetailModel *model = [TaskDetailModel mj_objectWithKeyValues:dict2];
                
                [self.dataArray addObject:model];
            }
        
        }
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TaskDetailModel *model = self.dataArray[indexPath.row];
    
    TaskDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    
    if (cell == nil) {
        
        cell = [TaskDetailCell WithTaskDetailCell];
    }
    
    cell.model = model;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    TaskDetailModel *model = self.dataArray[indexPath.row];
    PersonTaskController *perVC = [[PersonTaskController alloc] init];
    perVC.ID = model.ID;
    
    [self.navigationController pushViewController:perVC animated:YES];
}




@end







